﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using GraphCompiler.Core;
using GraphCompiler.Core.Parsing;
using GraphCompiler.Core.Exceptions;

namespace GraphCompiler.Specification.Parsing
{
    public class BoxParserSpecs
    {
        [TestFixture]
        public class when_parsing_empty_input
        {
            BoxParser _parser = new BoxParser();

            [Test]
            public void is_not_applicable()
            {
                bool isApplicable = _parser.IsApplicable(new TokenCollection());
                Assert.IsFalse(isApplicable);
            }

            [ExpectedException(typeof(SyntaxErrorException))]
            [Test]
            public void raises_error()
            {
                _parser.ParseTypedNode(new TokenCollection());
            }
        }

        [TestFixture]
        public class when_parsing_invalid_input
        {
            BoxParser _parser = new BoxParser();
            TokenCollection _invalidTokens = new TokenCollection("!", "foo");

            [Test]
            public void is_not_applicable()
            {
                bool isApplicable = _parser.IsApplicable(new TokenCollection("a", "!", "b"));
                Assert.IsFalse(isApplicable);
            }

            [ExpectedException(typeof(SyntaxErrorException))]
            [Test]
            public void raises_error()
            {
                _parser.ParseTypedNode(_invalidTokens);
            }
        }

        [TestFixture]
        public class when_parsing_empty_box_declaration
        {
            BoxParser _parser = new BoxParser();
            TokenCollection _tokens = new TokenCollection("box", "myBox", "{", "}");

            [Test]
            public void sets_name_to_specified_value()
            {
                var boxNode = _parser.ParseTypedNode(_tokens);

                Assert.AreEqual("myBox", boxNode.Name);
            }

            [Test]
            public void is_applicable()
            {
                Assert.IsTrue(_parser.IsApplicable(_tokens));
            }
        }
    }
}
